<!--页面主要内容-->
<main class="lyear-layout-content">
    <div class="container-fluid p-t-15">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-toolbar d-flex flex-column flex-md-row">
                        <div class="toolbar-btn-action">
                            <a class="btn btn-primary m-r-5" href="{:url('admin/vip/add',['proid' => $proid])}"><i
                                    class="mdi mdi-plus"></i> 新增</a>
                            <a class="btn btn-danger dels"><i class="mdi mdi-window-close"></i> 删除</a>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="check-all">
                                                <label class="custom-control-label" for="check-all"></label>
                                            </div>
                                        </th>
                                        <th>编号</th>
                                        <th>会员等级</th>
                                        <th>等级价格</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {if count($VipList)>0}
                                    {foreach $VipList as $key => $item}
                                    <tr>
                                        <td>
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input ids" name="ids[]"
                                                    value="{$item.id}" id="ids-{$item.id}">
                                                <label class="custom-control-label" for="ids-{$item.id}"></label>
                                            </div>
                                        </td>
                                        <td>{$key + ($page - 1) * $num + 1}</td>
                                        <td>{$item.level}级</td>
                                        <td>{$item.price}</td>
                                        <td>
                                            <div class="btn-group">
                                                <a class="btn btn-xs btn-default"
                                                    href="{:url('admin/vip/edit',['proid' => $proid,'vipid' => $item.id])}"
                                                    title="" data-toggle="tooltip" data-original-title="编辑"><i
                                                        class="mdi mdi-pencil"></i></a>
                                                <a class="btn btn-xs btn-default del" data-id="{$item.id}"
                                                    data-toggle="tooltip" data-original-title="删除"><i
                                                        class="mdi mdi-window-close"></i></a>
                                            </div>
                                        </td>
                                    </tr>
                                    {/foreach}
                                    {else}
                                    <tr>
                                        <td colspan="5" align="center">该商品暂无会员价格</td>
                                    </tr>
                                    {/if}
                                </tbody>
                            </table>
                        </div>
                        {$VipList|raw}
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<!--End 页面主要内容-->
<script>
    function GetID() {
        var IdArr = []
        $('input[name="ids[]"]:checked').each(function (index, item) {
            IdArr.push(item.value)
        })
        return IdArr
    }
    $('.del').click(function () {
        $.confirm({
            title: '删除',
            content: '确认删除？',
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-info',
                    action: () => {
                        // 获取要删除的id
                        let vipid = $(this).data('id')
                        $.ajax({
                            type: 'post',
                            url: `{:url('admin/vip/del')}`,
                            data: {
                                action:'del',
                                vipid
                            },
                            dataType: 'json',
                            success: (result) => {
                                if (result.code === 1) {
                                    $.notify({
                                        message: result.msg,
                                    }, {
                                        delay: 1000,
                                        type: 'success',
                                        onClose: function () {
                                            location.reload();
                                        }
                                    })
                                } else {
                                    $.notify({
                                        message: result.msg,
                                    }, {
                                        delay: 1000,
                                        type: 'warning'
                                    })
                                }
                            }
                        })
                    }
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-danger'
                }
            }
        })
    })

    $('.dels').click(function () {
        $.confirm({
            title: '批量删除',
            content: '确认批量删除？',
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-info',
                    action: () => {
                        // 获取要删除的id
                        let ids = GetID()

                        $.ajax({
                            type: 'post',
                            url: `{:url('admin/vip/del')}`,
                            data: {
                                action:'dels',
                                ids
                            },
                            dataType: 'json',
                            success: (result) => {
                                if (result.code === 1) {
                                    $.notify({
                                        message: result.msg,
                                    }, {
                                        delay: 1000,
                                        type: 'success',
                                        onClose: function () {
                                            location.reload()
                                        }
                                    })
                                } else {
                                    $.notify({
                                        message: result.msg,
                                    }, {
                                        delay: 1000,
                                        type: 'warning'
                                    })
                                }
                            }
                        })
                    }
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-danger'
                }
            }
        })

    })
</script>